package com.bread.tliaswebmanagement.controller;

import com.bread.tliaswebmanagement.pojo.Emp;
import com.bread.tliaswebmanagement.pojo.LoginResult;
import com.bread.tliaswebmanagement.pojo.Result;
import com.bread.tliaswebmanagement.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private EmpService empService;
    @PostMapping
    public Result Login(@RequestBody Emp emp){
        log.info("登录请求:{}", emp);
        LoginResult loginResult = empService.login(emp);
        if (loginResult != null) {
            log.info("登录成功:{}", loginResult);
            return Result.success(loginResult);
        } else {
            log.info("登录失败");
            return Result.error("用户名或密码错误");
        }
    }


}
